package cn.qzbook.service;

import cn.qzbook.dao.UserDao;
import cn.qzbook.dao.UserDaoJDBC;
import cn.qzbook.domain.User;
import cn.qzbook.util.MyBatisUtil;

import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;

public class UserService {

    private UserDaoJDBC dao = new UserDaoJDBC();

    private UserDao daoMapper = MyBatisUtil.sqlSession().getMapper(UserDao.class);

    public List<User> selectUserByJDBC(Integer id,String name){

        return dao.selectUser(id,name);
    }

    public List<User> selectUserByMapper(Integer id,String name){

        return daoMapper.selectUser(id,name);
    }

    public void changeSexBatch(String sex,String[] ids){
        if (sex == null || "".equals(sex) || ids == null || ids.length < 0) return;
       Integer[] copyIds = new Integer[ids.length];
        for (int i = 0; i < ids.length; i ++) {
            copyIds[i] = Integer.parseInt(ids[i]);
        }
        daoMapper.changeSexBatch(sex,copyIds);
    }
}
